1. extract PPI data

library(clusterProfiler)
## 
## clusterProfiler v4.16.0 Learn more at https://yulab-smu.top/contribution-knowledge-mining/
## 
## Please cite:
## 
## G Yu. Thirteen years of clusterProfiler. The Innovation. 2024,
## 5(6):100722
## 
## Attaching package: 'clusterProfiler'
## The following object is masked from 'package:stats':
## 
##     filter
library(igraph)
## 
## Attaching package: 'igraph'
## The following object is masked from 'package:clusterProfiler':
## 
##     simplify
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
seed.protein <- c("APP", "PSEN1", "PSEN2", "APOE", "TREM2", "CR1")
protein.info <- read.table("./9606.protein.info.v12.0.txt", sep='\t', header=T, check.names=F, comment.char="", quote="")
head(protein.info[,seq(2)])
##     #string_protein_id preferred_name
## 1 9606.ENSP00000000233           ARF5
## 2 9606.ENSP00000000412           M6PR
## 3 9606.ENSP00000001008          FKBP4
## 4 9606.ENSP00000001146        CYP26B1
## 5 9606.ENSP00000002125        NDUFAF7
## 6 9606.ENSP00000002165          FUCA2
ppi <- read.table("./9606.protein.links.v12.0.txt", header = T, check.names = F, comment.char = "", quote = "")

seed.protein2 <- protein.info[protein.info$preferred_name %in% seed.protein, 1]

target.ppi <- ppi |> dplyr::filter(protein1 %in%  seed.protein2 | protein2 %in% seed.protein2) |>
    dplyr::filter(combined_score>600)

target.ppi$protein1 <- protein.info[match(target.ppi$protein1, protein.info$`#string_protein_id`), 2]
target.ppi$protein2 <- protein.info[match(target.ppi$protein2, protein.info$`#string_protein_id`), 2]

target.ppi |> write.table("./target_ppi.tsv", sep="\t", row.names=F, col.names=T, quote=F)

2. build igraph object

## load ppi network
target_ppi_g <- graph_from_data_frame(target.ppi, directed=FALSE)
target_ppi_g |> V() |> length()
## [1] 571
target_ppi_g |> E() |> length()
## [1] 1674
## simplify network
g_ppi <- simplify(target_ppi_g, remove.multiple = FALSE, remove.loops = TRUE)

g_ppi <- simplify(g_ppi, remove.multiple = TRUE, remove.loops = FALSE,
                  edge.attr.comb = "max")

3. Network topological analysis

## load TCMDATA locally
# remotes::install_github("Hinna0818/TCMDATA)
# library(TCMDATA)
devtools::load_all("/Users/hinna/TCMDATA")
## ℹ Loading TCMDATA
## compute node info
g_ppi <- compute_nodeinfo(g_ppi)
## Calculating degree / strength ...
## Calculating betweenness (unweighted) ...
## Calculating closeness (unweighted) ...
## Calculating eigenvector centrality ...
## Calculating PageRank ...
## Calculating coreness (k-core) ...
## Calculating local clustering coefficient ...
## Calculating eccentricity ...
## Detecting articulation points ...
## Calculating MCC ...
## Calculating MNC ...
## Calculating DMNC ...
## Calculating BottleNeck (BN) ...
## Calculating radiality ...
## Calculating Stress ...
## Calculating EPC ...
##   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |==                                                                    |   4%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |=========                                                             |  13%  |                                                                              |=========                                                             |  14%  |                                                                              |==========                                                            |  14%  |                                                                              |==========                                                            |  15%  |                                                                              |===========                                                           |  15%  |                                                                              |===========                                                           |  16%  |                                                                              |============                                                          |  16%  |                                                                              |============                                                          |  17%  |                                                                              |============                                                          |  18%  |                                                                              |=============                                                         |  18%  |                                                                              |=============                                                         |  19%  |                                                                              |==============                                                        |  19%  |                                                                              |==============                                                        |  20%  |                                                                              |==============                                                        |  21%  |                                                                              |===============                                                       |  21%  |                                                                              |===============                                                       |  22%  |                                                                              |================                                                      |  22%  |                                                                              |================                                                      |  23%  |                                                                              |================                                                      |  24%  |                                                                              |=================                                                     |  24%  |                                                                              |=================                                                     |  25%  |                                                                              |==================                                                    |  25%  |                                                                              |==================                                                    |  26%  |                                                                              |===================                                                   |  26%  |                                                                              |===================                                                   |  27%  |                                                                              |===================                                                   |  28%  |                                                                              |====================                                                  |  28%  |                                                                              |====================                                                  |  29%  |                                                                              |=====================                                                 |  29%  |                                                                              |=====================                                                 |  30%  |                                                                              |=====================                                                 |  31%  |                                                                              |======================                                                |  31%  |                                                                              |======================                                                |  32%  |                                                                              |=======================                                               |  32%  |                                                                              |=======================                                               |  33%  |                                                                              |=======================                                               |  34%  |                                                                              |========================                                              |  34%  |                                                                              |========================                                              |  35%  |                                                                              |=========================                                             |  35%  |                                                                              |=========================                                             |  36%  |                                                                              |==========================                                            |  36%  |                                                                              |==========================                                            |  37%  |                                                                              |==========================                                            |  38%  |                                                                              |===========================                                           |  38%  |                                                                              |===========================                                           |  39%  |                                                                              |============================                                          |  39%  |                                                                              |============================                                          |  40%  |                                                                              |============================                                          |  41%  |                                                                              |=============================                                         |  41%  |                                                                              |=============================                                         |  42%  |                                                                              |==============================                                        |  42%  |                                                                              |==============================                                        |  43%  |                                                                              |==============================                                        |  44%  |                                                                              |===============================                                       |  44%  |                                                                              |===============================                                       |  45%  |                                                                              |================================                                      |  45%  |                                                                              |================================                                      |  46%  |                                                                              |=================================                                     |  46%  |                                                                              |=================================                                     |  47%  |                                                                              |=================================                                     |  48%  |                                                                              |==================================                                    |  48%  |                                                                              |==================================                                    |  49%  |                                                                              |===================================                                   |  49%  |                                                                              |===================================                                   |  50%  |                                                                              |===================================                                   |  51%  |                                                                              |====================================                                  |  51%  |                                                                              |====================================                                  |  52%  |                                                                              |=====================================                                 |  52%  |                                                                              |=====================================                                 |  53%  |                                                                              |=====================================                                 |  54%  |                                                                              |======================================                                |  54%  |                                                                              |======================================                                |  55%  |                                                                              |=======================================                               |  55%  |                                                                              |=======================================                               |  56%  |                                                                              |========================================                              |  56%  |                                                                              |========================================                              |  57%  |                                                                              |========================================                              |  58%  |                                                                              |=========================================                             |  58%  |                                                                              |=========================================                             |  59%  |                                                                              |==========================================                            |  59%  |                                                                              |==========================================                            |  60%  |                                                                              |==========================================                            |  61%  |                                                                              |===========================================                           |  61%  |                                                                              |===========================================                           |  62%  |                                                                              |============================================                          |  62%  |                                                                              |============================================                          |  63%  |                                                                              |============================================                          |  64%  |                                                                              |=============================================                         |  64%  |                                                                              |=============================================                         |  65%  |                                                                              |==============================================                        |  65%  |                                                                              |==============================================                        |  66%  |                                                                              |===============================================                       |  66%  |                                                                              |===============================================                       |  67%  |                                                                              |===============================================                       |  68%  |                                                                              |================================================                      |  68%  |                                                                              |================================================                      |  69%  |                                                                              |=================================================                     |  69%  |                                                                              |=================================================                     |  70%  |                                                                              |=================================================                     |  71%  |                                                                              |==================================================                    |  71%  |                                                                              |==================================================                    |  72%  |                                                                              |===================================================                   |  72%  |                                                                              |===================================================                   |  73%  |                                                                              |===================================================                   |  74%  |                                                                              |====================================================                  |  74%  |                                                                              |====================================================                  |  75%  |                                                                              |=====================================================                 |  75%  |                                                                              |=====================================================                 |  76%  |                                                                              |======================================================                |  76%  |                                                                              |======================================================                |  77%  |                                                                              |======================================================                |  78%  |                                                                              |=======================================================               |  78%  |                                                                              |=======================================================               |  79%  |                                                                              |========================================================              |  79%  |                                                                              |========================================================              |  80%  |                                                                              |========================================================              |  81%  |                                                                              |=========================================================             |  81%  |                                                                              |=========================================================             |  82%  |                                                                              |==========================================================            |  82%  |                                                                              |==========================================================            |  83%  |                                                                              |==========================================================            |  84%  |                                                                              |===========================================================           |  84%  |                                                                              |===========================================================           |  85%  |                                                                              |============================================================          |  85%  |                                                                              |============================================================          |  86%  |                                                                              |=============================================================         |  86%  |                                                                              |=============================================================         |  87%  |                                                                              |=============================================================         |  88%  |                                                                              |==============================================================        |  88%  |                                                                              |==============================================================        |  89%  |                                                                              |===============================================================       |  89%  |                                                                              |===============================================================       |  90%  |                                                                              |===============================================================       |  91%  |                                                                              |================================================================      |  91%  |                                                                              |================================================================      |  92%  |                                                                              |=================================================================     |  92%  |                                                                              |=================================================================     |  93%  |                                                                              |=================================================================     |  94%  |                                                                              |==================================================================    |  94%  |                                                                              |==================================================================    |  95%  |                                                                              |===================================================================   |  95%  |                                                                              |===================================================================   |  96%  |                                                                              |====================================================================  |  96%  |                                                                              |====================================================================  |  97%  |                                                                              |====================================================================  |  98%  |                                                                              |===================================================================== |  98%  |                                                                              |===================================================================== |  99%  |                                                                              |======================================================================|  99%  |                                                                              |======================================================================| 100%
## show basic metrics
V(g_ppi)$degree |> table()
## 
##   1   2   3   4   5  45  54  74 100 244 330 
## 374 145  27  13   6   1   1   1   1   1   1
## show the relationship between cci and degree and betweenness
library(tidygraph)
## 
## Attaching package: 'tidygraph'
## 
## The following object is masked from 'package:igraph':
## 
##     groups
## 
## The following object is masked from 'package:stats':
## 
##     filter
library(tibble)
## 
## Attaching package: 'tibble'
## 
## The following object is masked from 'package:igraph':
## 
##     as_data_frame
library(ggfun)
## ggfun v0.2.0 Learn more at https://yulab-smu.top/
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
library(ggrepel)
library(ggiraph)

g_ppi |> as_tbl_graph() |>
  activate('nodes') |>
  tibble::as_tibble() |>
  ggplot(aes(x = degree, y = clustering_coef, size = betweenness)) +
   geom_point() +
   geom_text_repel(data = td_filter(degree > 80), mapping = aes(label = name)) ## It is a zero-scale network

show the PPI network

library(ggtangle)
## ggtangle v0.0.7 Learn more at https://yulab-smu.top/
library(ggiraph)
library(ggraph)
p1 <- ggtangle::ggplot(g_ppi, layout = "kk") +
  geom_edge(alpha = 0.4) +
  geom_text_repel(data = td_filter(degree > 60), aes(label = name), size = 3, segment.color = NA, colour = "red2", fontface = "bold") +
  geom_point(aes(color = degree, size = betweenness)) + 
  scale_color_viridis_c() 

p1

p11 <- ggraph(g_ppi, layout = 'kk') +
 geom_edge_link() +
 geom_point_interactive(
   mapping = aes(
     x = x, y = y, 
     color = betweenness, 
     tooltip = name,
     data_id = name
     )
 ) +
 geom_text_repel(data = td_filter(degree > 60),
   mapping = aes(x = x, y = y, label = name), bg.color ='white'
 ) +
 scale_color_viridis_c() +
 theme_graph()

girafe(ggobj = p11)

4. Network community analysis

## louvain clustering
set.seed(42)
g_ppi <- run_louvain(g_ppi)
## No weights found. Running unweighted clustering.
## Running Louvain (Resolution: 1.0)...
## Done! Identified 5 modules (Modularity: 0.472).
p2 <- ggtangle::ggplot(g_ppi, layout = "kk") +
  geom_edge(alpha = 0.4) +
  geom_point(aes(color = as.factor(louvain_cluster), size = betweenness)) +
  geom_text_repel(data = td_filter(degree > 60), aes(label = name), size = 3, segment.color = NA, colour = "red2", fontface = "bold") +
  scale_color_viridis_d() +
  labs(color = "Cluster")
p2

Feature selection

topnodes_info <- rank_ppi_nodes(g = g_ppi)
## Available metrics in graph: name, degree, strength, betweenness, betweenness_w, closeness, closeness_w, eigen_centrality, pagerank, coreness, clustering_coef, eccentricity, is_articulation, MCC, MNC, DMNC, BN, radiality, Stress, EPC, louvain_cluster
## Using the following metrics for ranking: degree, betweenness_w, closeness_w, eccentricity, radiality, Stress, MCC, MNC, DMNC, BN, EPC
g_ppi <- topnodes_info[["graph"]]
topnodes <- topnodes_info[["table"]]

## radar plot
node_profile <- get_node_profile(topnodes, node_name = "APOE",
                                 metrics = c("degree", 
                                         "betweenness", 
                                         "closeness",
                                         "MCC", 
                                         "MNC", 
                                         "pagerank", 
                                         "coreness", 
                                         "EPC"))
p_radar <- radar_plot(node_profile, title = "Centrality score of APOE")
p_radar

5. Network functional modules analysis

library(enrichplot)
## Warning: package 'enrichplot' was built under R version 4.5.1
## enrichplot v1.28.4 Learn more at https://yulab-smu.top/contribution-knowledge-mining/
## 
## Please cite:
## 
## Guangchuang Yu, Li-Gen Wang, Guang-Rong Yan, Qing-Yu He. DOSE: an
## R/Bioconductor package for Disease Ontology Semantic and Enrichment
## analysis. Bioinformatics. 2015, 31(4):608-609
## 
## Attaching package: 'enrichplot'
## The following object is masked from 'package:ggfun':
## 
##     volplot
library(org.Hs.eg.db)
## Loading required package: AnnotationDbi
## Loading required package: stats4
## Loading required package: BiocGenerics
## Loading required package: generics
## 
## Attaching package: 'generics'
## The following object is masked from 'package:TCMDATA':
## 
##     components
## The following objects are masked from 'package:igraph':
## 
##     components, union
## The following objects are masked from 'package:base':
## 
##     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
##     setequal, union
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:igraph':
## 
##     normalize, path
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, aperm, append, as.data.frame, basename, cbind,
##     colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
##     get, grep, grepl, is.unsorted, lapply, Map, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
##     rbind, Reduce, rownames, sapply, saveRDS, table, tapply, unique,
##     unsplit, which.max, which.min
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## 
## Attaching package: 'Biobase'
## The following object is masked from 'package:TCMDATA':
## 
##     content
## Loading required package: IRanges
## Loading required package: S4Vectors
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:tidygraph':
## 
##     active, rename
## The following object is masked from 'package:clusterProfiler':
## 
##     rename
## The following object is masked from 'package:utils':
## 
##     findMatches
## The following objects are masked from 'package:base':
## 
##     expand.grid, I, unname
## 
## Attaching package: 'IRanges'
## The following object is masked from 'package:tidygraph':
## 
##     slice
## The following objects are masked from 'package:TCMDATA':
## 
##     desc, slice
## The following object is masked from 'package:clusterProfiler':
## 
##     slice
## 
## Attaching package: 'AnnotationDbi'
## The following object is masked from 'package:tidygraph':
## 
##     select
## The following object is masked from 'package:TCMDATA':
## 
##     select
## The following object is masked from 'package:clusterProfiler':
## 
##     select
## 
module.genes <- g_ppi |> as_tbl_graph() |> activate('nodes') |>tibble::as_tibble()

module.ora.res <- compareCluster(name ~ louvain_cluster, data = module.genes, fun = enrichGO, keyType = "SYMBOL", OrgDb=org.Hs.eg.db, ont = "BP")

dotplot(module.ora.res, label_format = 70)
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## ℹ The deprecated feature was likely used in the enrichplot package.
##   Please report the issue at
##   <https://github.com/GuangchuangYu/enrichplot/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

choose cluster 1 for further functional enrichment analysis

# select cluster 1 nodes
c1_nodes <- V(g_ppi)$name[V(g_ppi)$louvain_cluster == "1"]
subg_cluster1 <- induced_subgraph(g_ppi, vids = c1_nodes)

# cluster 1 enrichment analysis
c1 <- enrichGO(c1_nodes, OrgDb='org.Hs.eg.db', keyType="SYMBOL", ont = "all")
c1go <- gglollipop(c1, line.col = "orange", split = "ONTOLOGY",
                   line.type = "dashed", palette = "PiYG", top_n = 5, show_count = F) + 
  facet_grid(ONTOLOGY ~ ., scales = "free_y") +
  theme(strip.text.y = element_text(angle = 0)) 
c1go